package com.timothy.android;


import com.timothy.service.MessageReceiveService;
import com.timothy.service.MessageSender;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class LoginActivity extends BaseActivity {
	/** Called when the activity is first created. */
	private EditText hostAddr = null;
	private EditText hostPort = null;
	private Button loginBtn = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		
		hostAddr = (EditText) this.findViewById(R.id.hostAddr);
		hostPort = (EditText) this.findViewById(R.id.hostPort);
		
		loginBtn = (Button) this.findViewById(R.id.loginBtn);
		loginBtn.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				MessageSender.PC_IP =  hostAddr.getText().toString();
				MessageSender.PC_PORT = Integer.valueOf( hostPort.getText().toString() );
				//Send Phone Information to PC
				if( MessageSender.sendMessage( MessageSender.Get_Base_Stations ) ) {
					//todo... can not do any operation
				} else {
					ShowDialog("不能连接到指定IP的端口，请重新设置");
				}	
			}			
		});
	}

	@Override
	protected void processMessage(int what, String content) {
		Log.i("LoginActivity","what="+what+" content=" + content);
		if( MessageReceiveService.MSG_BASE_STATION == what ) {
			Intent intent = new Intent();
			intent.putExtra("value", content);
			intent.setClass( getBaseContext(), BaseStations.class);
			startActivity(intent);
		}
	}
	
}
